<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <link rel="icon" type="image/x-icon" th:href="${application.iconPath}"/>
    <div th:include="../templates/aaacommon/basic::html_header"></div>
    <title class="projectName"></title>
</head>
<body>
<div style="margin-left: 100px;margin-top: 100px;">
    <h2 th:text="${info}"></h2>
    <h2 id="info"></h2>
    <div id="login_select" style="margin-top: 20px;">
        <button class="layui-btn" id="login">login</button>
        <button class="layui-btn" id="cas_login">cas login</button>
    </div>
</div>

</body>
<input type="hidden" id="casLoginUrl" th:value="${casLoginUrl}"/>
<input type="hidden" id="casVerifyLogin" th:value="${casVerifyLogin}"/>
<input type="hidden" id="casSaveLogin" th:value="${casSaveLogin}"/>
<script>
    layui.use(['element', 'form', 'layer', 'web', 'user'], function () {
        var element = layui.element;
        var form = layui.form;
        var layer = layui.layer;
        var web = layui.web;
        var user = layui.user;

        var casId = getUrlParam("casId");
        if (casId != null && casId.length > 0) {
            var url = basePath + "/user/saveCasLogin";
            web.ajax_sync(url, 'post', {casId: casId}, function (data) {
                // cookie 保存成功后,去掉url 后面的参数,主要是为了美观,防止第二次保存cookie
                var local_url = location.href;
                local_url = local_url.substring(0, local_url.indexOf("?"));
                location.href = local_url;
            });
        }
        // 判断用户是否登录
        var sessionId =user.getSessionId();
        if (sessionId != null && sessionId.length > 0) {
            $("#info").html(sessionId);
            $("#login_select").hide();
        } else {
            $("#info").html("没有登录");
            $("#login_select").show();
        }

        $("#login").click(function () {
            location.href = basePath + "/index/login";
        });
        $("#cas_login").click(function () {
            location.href = $("#casLoginUrl").val() + "?redirect_url=" + encodeURIComponent(location.href);
        });
    });
</script>
<div th:include="../templates/aaacommon/basic::html_footer"></div>
</html>